package DynamicProgrammingPackage;

public class change_ {
    public static void main(String[] args) {
        System.out.println(change(5, new int[]{1, 2, 5}));
    }

    // 1. dp[i]表示总金额为i一共有dp[i]种
    // 2. 递推公式: dp[i] = Math.max(dp[j],dp[j - coins[i]] + 1)
    // 3. 初始化: dp[0] = 0;
    // 4. 遍历顺序: 先遍历物品后遍历背包且正向遍历
    public static int change(int amount, int[] coins) {
        int[] dp = new int[amount + 1];
        dp[0] = 1;
        for (int i = 0; i < coins.length; i++) {
            for (int j = coins[i]; j <= amount; j++) {
                dp[j] += dp[j - coins[i]];
            }
        }
        return dp[amount];
    }
}
